package com.stottlerhenke.simbionic.editor.parser;

import com.stottlerhenke.simbionic.api.SB_VarType;

public class SB_StringConstantNode extends SB_ConstantNode {
  private String _value;
  private boolean _symbol;
  public SB_StringConstantNode(String value) {
	  this(value, false);
  }
  public SB_StringConstantNode(String value, boolean symbol) {
	    super(SB_VarType.kString);
	    _value = value;
	    _symbol = symbol;
  }

  public String ToString()
  {
	  if (_symbol)
		  return _value;
	  else
      {
	      // re-escape all escape chars that were stripped by the parser
          StringBuffer buff = new StringBuffer("\"");
          for (int index=0; index < _value.length(); ++index)
          {
              switch (_value.charAt(index))
              {
              case '"': buff.append("\\\""); break;
              case '\\': buff.append("\\\\"); break;
              case '\t': buff.append("\\t"); break;
              case '\n': buff.append("\\n"); break;
              default: buff.append(_value.charAt(index)); break;
              }
          }
          return buff.append("\"").toString();
      }
  }
  
  public String GetStringValue() { return _value; }

}